package leetcode.二叉树;

import leetcode.TreeNode;

public class Leetcode572 {
    public boolean isSubtree(TreeNode s, TreeNode t) {
        if(s==null&&t==null){
            return true;
        }
        if(t!=null&&s==null){
            return false;
        }
        return isSubtree(s.left,t)||isSubtree(s.right,t)||isSame(s,t);
    }

    public boolean isSame(TreeNode s, TreeNode t){
        if(s==null&&t==null){
            return true;
        }
        if(s==null||t==null){
            return false;
        }
        return s.val == t.val&&isSame(s.left,t.left)&&isSame(s.right,t.right);
    }
}
